
* Summary statistics
use "${data_out_folder}/wave1_wave2_final.dta", clear

file open quotas using "${table_folder}/tab_A1.tex", write replace

file write quotas "\begin{tabular}{l ccc}" _n
file write quotas "\hline" _n
file write quotas "\hline" _n
file write quotas "\addlinespace" _n
file write quotas "Variable & Wave 1 & Wave 2 & US population (2019) \\" _n
file write quotas "\addlinespace" _n
file write quotas "\hline" _n
file write quotas "\addlinespace" _n

gen republican = 1 - democrat if !missing(democrat)
gen income_below_50k = hh_income < 50000 if !missing(hh_income)
gen income_below_50k_to_100k = 50000 <= hh_income & hh_income < 100000 if !missing(hh_income)
gen income_100k = 100000 <= hh_income if !missing(hh_income)

sum if wave == 1
local obs_wave1 = r(N)

foreach var in female age_1834 age_3554 age_55 bachelor_above region_northeast region_midwest region_south region_west democrat republican income_below_50k income_below_50k_to_100k income_100k{
	sum `var' if wave == 1
	local `var'_wave1 = round(r(mean) * 100, 1)
}

sum if wave == 2
local obs_wave2 = r(N)

foreach var in female age_1834 age_3554 age_55 bachelor_above region_northeast region_midwest region_south region_west democrat republican income_below_50k income_below_50k_to_100k income_100k{
	sum `var' if wave == 2
	local `var'_wave2 = round(r(mean) * 100, 1)
}

file write quotas "Female & `female_wave1'\% & `female_wave2'\% & 51\%\\" _n
file write quotas "Age: 18-34 & `age_1834_wave1'\% & `age_1834_wave2'\% & 30\%\\" _n
file write quotas "Age: 35-54 & `age_3554_wave1'\% & `age_3554_wave2'\% & 32\%\\" _n
file write quotas "Age: 55+ & `age_55_wave1'\% & `age_55_wave2'\% & 38\%\\" _n
file write quotas "Education: Bachelor's degree or above & `bachelor_above_wave1'\% & `bachelor_above_wave2'\% & 31\%\\" _n
file write quotas "Region: Northeast & `region_northeast_wave1'\% & `region_northeast_wave2'\% & 17\%\\" _n
file write quotas "Region: Midwest & `region_midwest_wave1'\% & `region_midwest_wave2'\% & 21\%\\" _n
file write quotas "Region: South & `region_south_wave1'\% & `region_south_wave2'\% & 38\%\\" _n
file write quotas "Region: West & `region_west_wave1'\% & `region_west_wave2'\% & 24\%\\" _n
file write quotas "Democrat*    & `democrat_wave1'\% & `democrat_wave2'\% & 52\%\\" _n
file write quotas "Republican*    & `republican_wave1'\% & `republican_wave2'\% & 47\%\\" _n
file write quotas "Income: Below 50k*   & `income_below_50k_wave1'\% & `income_below_50k_wave2'\% & 37\%\\" _n
file write quotas "Income: 50k to 100k*   & `income_below_50k_to_100k_wave1'\% & `income_below_50k_to_100k_wave2'\% & 31\%\\" _n
file write quotas "Income: Above 100k*   & `income_100k_wave1'\% & `income_100k_wave2'\% & 31\%\\" _n
file write quotas "\hline" _n
file write quotas "\hline" _n
file write quotas "\end{tabular}"
file close quotas

